<?php
  session_cache_limiter('private,must-revalide');
   /**
   * 处理上传页面
   */ 
    include_once("../config.php");
    $id= $_POST['id'];	
	$cate_id = 0; //分类
	//date_default_timezone_set('Asia/Shanghai');	
	$time=date('Y-m-d H:i:s');
    $ch_headline =$_POST["ch_headline"];		//中文标题
    $search = "SELECT * FROM $TBL_NEWS WHERE ch_headline='$ch_headline' and id!=$id";
	$result = mysql_query( $search );
	if( @mysql_num_rows( $result ) > 0 )
	{
		MyNotice("該標題命名已存在,請換個標題試試！");
		exit();
	}
   	$ch_text = work_str($_POST["chinese_edit"], 1);				//中文内容	
	$ch_source= work_str($_POST['ch_source'],1);						//中文来源
	$en_headline = work_str($_POST["en_headline"], 1);			//英文标题
	$en_text = work_str($_POST["english_edit"], 1);					//中英内容
	$en_source = work_str($_POST["en_source"], 1);			    //英文来源
	$cont1 = array("<p>","</p>");
	$cont2 = array("","</br>");
	$ch_text1 = str_replace($cont1, $cont2, $ch_text);
	$en_text1 = str_replace($cont1, $cont2, $en_text);
	$sql_up="select * from $TBL_CATE where cate_id='$cate_id'";
	$result_up=mysql_query($sql_up);
	$row_up=mysql_fetch_array($result_up);
	$ch_cate_name = $row_up['zh_cate_title'];
	$en_cate_name = $row_up['en_cate_title'];	
	$user_id = $_SESSION['user_id'];
	$img = $_FILES['img']['name'];	
	if($img=='')
	{
		$query = "UPDATE $TBL_NEWS SET
		ch_headline='$ch_headline',ch_source='$ch_source',ch_text='$ch_text',ch_cate_name='$ch_cate_name',
		en_headline='$en_headline',en_source='$en_source',en_text='$en_text',en_cate_name='$en_cate_name',
		date_added='$time',date_up ='$time',user_id='$user_id' where id=$id";	
	}else{
		$query = "UPDATE $TBL_NEWS SET
		ch_headline='$ch_headline',ch_source='$ch_source',ch_text='$ch_text',ch_cate_name='$ch_cate_name',
		en_headline='$en_headline',en_source='$en_source',en_text='$en_text',en_cate_name='$en_cate_name',
		date_added='$time',date_up ='$time',user_id='$user_id' where id=$id";	
	
	}    	
    $res = mysql_query($query) or die(mysql_error());
	$insert_id = $id;	
	if($_FILES['img']['name']!='')
	{		
		@mkdir($conf['fck_upload'] . "news/".$insert_id);
		@chmod($conf['fck_upload'] . "news/".$insert_id,0777);
		@mkdir($conf['fck_upload'] . "news/".$insert_id."/homeimage");
		@chmod($conf['fck_upload'] . "news/".$insert_id,"/homeimage",0777);	
		$img_file =$conf['fck_upload'] . "news/".$insert_id."/homeimage";
		$file_full = $img_file."/".$img;
		$upload_file = $_FILES['img']['tmp_name'];          //上传过来的压缩文件
		move_uploaded_file($upload_file, $file_full);       //上传到指定文件夹		
	}
	for($i=0; $i<count($_FILES['upfile']['name']); $i++) 
	{       				  
		$name = $_FILES['upfile']['name'][$i];
		if($name!='')
		{
			@mkdir($conf['fck_upload'] . "news/".$insert_id);
			@chmod($conf['fck_upload'] . "news/".$insert_id,0777);
			$save_file = $conf['fck_upload'] . "news/".$insert_id;   //存上传文件的文件夹
			$save_path = $save_file;			
			$file_name = $name;	
			$file_full = $save_path .'/'. $file_name; 
			$upload_file = $_FILES['upfile']['tmp_name'][$i]; //上传过来的压缩文件
			move_uploaded_file($upload_file, $file_full);       //上传到指定文件夹
			chmod($file_full,0777);
			$query1="INSERT INTO $TBL_PIC SET NEW_ID='$insert_id',name='$name',type=0,IMG_NAME='$file_name',REG_TIME='$time'";
			$result1 = mysql_query($query1) or die(mysql_error());
		}
	 
	}
		 MyNotice("生活情報修改成功", 1, "../news.php");
		 exit(0);  
  
?>